<template>
	<view>
		<input class="input" type="text" placeholder="请输入用户名" v-model="userId" placeholder-class="placehoder" />
		<view class="btnview">
			<button class="btn white" @click="login">登录</button>
			<button class="btn white" @click="gotoAppPermissionSetting">设置权限</button>
			<button class="btn white" @click="requestAndroidPermission">打开摄像头</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				sdkAppId: 0,
				userId: 'user1',
				userSig: "",
				selfInfo: {},
			}
		},
		methods: {
			setDelegate() {
				this.$lobster.live.setDelegate(res => {
					console.log(JSON.stringify(res));
					// this.$util.showToast(JSON.stringify(res))
				})
			},
			login() {
				if (this.userId) {
					console.log("livelogin");
					this.sdkAppId = this.$lobster.clound.sdkappId;
					console.log("livelogin_1111111111");
					this.$lobster.userdata.forEach(item => {
						if (item.userId == this.userId) {
							this.selfInfo = item;
							this.userSig = item.userSig;
						}
					});
					console.log("livelogin_222222");
					if (!this.selfInfo.userId) {
						this.$util.showToast('用户不存在');
						return;
					}
					console.log("livelogin_3333");
					this.$lobster.live.login(this.sdkAppId, this.userId, this.userSig, res => {
						console.log("livelogin_4444444");
						console.log(res);
						this.$store.commit('updateMyInfo', {
							NickName: this.selfInfo.user,
							HeadImg: this.selfInfo.img,
							userId: this.selfInfo.userId,
						});
						this.$util.showToast(JSON.stringify(res))
						if (res.code == 0) {
							this.$util.navigateTo('/pages/live/liveroom');
						}
					})
				} else {
					this.$util.showToast('请输入用户名');
				}

			},
			logout() {
				this.$lobster.live.logout(res => {
					console.log(res);
					this.$util.showToast(JSON.stringify(res))
				})
			},
			setSelfProfile() {
				this.$lobster.live.setSelfProfile('测试1', 'https://oss.mcloudsoft.cn/20210915/c4420d71-39a2-4ce4-936c-1a6903b0fe0e.png',
					res => {
						console.log(res);
						this.$util.showToast(JSON.stringify(res))
					})
			},
			createRoom() {
				this.$util.navigateTo('/pages/live/liveroom');
			},
			gotoAppPermissionSetting() {
				this.$lobster.permission.gotoAppPermissionSetting();
			},
			requestAndroidPermission() {
				try {
					var pa = ['android.permission.CAMERA'];
					 
					plus.android.requestPermissions(
						pa,
						function(resultObj) {
							console.log(resultObj);
						},
						function(error) {
							 console.log(resultObj);
						}
					);
				} catch (e) {
					 console.log(e);
				}
			},
		}
	}
</script>

<style>
	.input {
		font-size: 32rpx;
		line-height: 60rpx;
		flex: 1;
		border: 2rpx #eee solid;
		height: 80rpx;
		margin: 10rpx 40rpx;
	}

	.btnview {
		margin: 20rpx;
	}

	.btn {
		box-sizing: border-box;
		//width: 100%;
		height: 80rpx;
		border-radius: 10rpx;
		font-size: 32rpx;
		line-height: 80rpx;
		margin: 20rpx;
	}

	.white {
		color: #ffffff;
		background-color: #4F91E2;
	}

	.placehoder {
		padding-left: 10rpx;
	}
</style>
